Add WHITESPACE delimiter to xcsv.
authoralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 27 Oct 2003 15:06:20 +0000 (15:06 +0000)
committeralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 27 Oct 2003 15:06:20 +0000 (15:06 +0000)
gpsbabel/csv_util.c
gpsbabel/internal_styles.c
gpsbabel/style/README.style
gpsbabel/style/gpsdrive.style
gpsbabel/xcsv.c

index 45e11d2e1b265e2506d9d6377ce279145cfd6e39..c5786dfaf5cc377f0ab9722372623172757a6ec3 100644 (file)
@@ -30,6 +30,7 @@
 #define LAT_DIR(a) a < 0.0 ? 'S' : 'N'
 #define LON_DIR(a) a < 0.0 ? 'W' : 'E'
 #define NONULL(a) a ? a : ""
+#define ISWHITESPACE(a) ((a == ' ') || (a == '\t'))
 
 /* convert excel time (days since 1900) to time_t and back again */
 #define EXCEL_TO_TIMET(a) ((a - 25569.0) * 86400.0)
@@ -165,11 +166,15 @@ csv_lineparse(const char *stringstart, const char *delimited_by,
     size_t dlen = 0, elen = 0;
     int enclosedepth = 0;
     short int dfound;
+    short int hyper_whitespace_delimiter = 0;
 
     if (tmp) {
        xfree(tmp);
        tmp = NULL;
     }
+    
+    if (strcmp(delimited_by, "\\w") == 0)
+        hyper_whitespace_delimiter = 1;
 
     if (!p) {
        /* first pass thru */
@@ -185,7 +190,7 @@ csv_lineparse(const char *stringstart, const char *delimited_by,
     sp = p;
 
     /* length of delimiters and enclosures */
-    if (delimited_by) 
+    if ((delimited_by) && (!hyper_whitespace_delimiter))
         dlen = strlen(delimited_by);
     if (enclosed_in)
         elen = strlen(enclosed_in);
@@ -200,13 +205,19 @@ csv_lineparse(const char *stringstart, const char *delimited_by,
                enclosedepth++;
        }
 
-       if ((!enclosedepth) && (strncmp(p, delimited_by, dlen) == 0)) {
-           dfound = 1;
-       } else {
-           p++;
+       if (!enclosedepth) {
+           if ((dlen) && (strncmp(p, delimited_by, dlen) == 0)) {
+               dfound = 1;
+           } else if ((hyper_whitespace_delimiter) && (ISWHITESPACE(*p))) {
+               dfound = 1;
+               while (ISWHITESPACE(*p))
+                   p++;
+           } else {
+               p++;
+           }
        }
     }
-
+    
     /* allocate enough space for this data field */
     tmp = xcalloc((p - sp) + 1, sizeof(char));
 
@@ -586,10 +597,15 @@ xcsv_waypt_pr(const waypoint *wpt)
     char *shortname = NULL;
     char *description = NULL;
     char * anyname = NULL;
+    char * write_delimiter;
     int i;
     field_map_t *fmp;
     queue *elem, *tmp;
 
+    if (strcmp(xcsv_file.field_delimiter, "\\w") == 0)
+        write_delimiter = " ";
+    else
+        write_delimiter = xcsv_file.field_delimiter;
     
     if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
         if (wpt->description) {
@@ -627,7 +643,7 @@ xcsv_waypt_pr(const waypoint *wpt)
         fmp = (field_map_t *) elem;
 
         if (i != 0) 
-            fprintf (xcsv_file.xcsvfp, xcsv_file.field_delimiter);
+            fprintf (xcsv_file.xcsvfp, write_delimiter);
 
         i++;
 
index 29b5b11eba8a8aaaffc2d68de9647ecea82fdb61..38e88b66fe91d99cb60771ea2c5060f1fd6fb29d 100644 (file)
@@ -187,7 +187,7 @@ static char gpsdrive[] =
 
 "# FILE LAYOUT DEFINITIIONS:\n"
 "#\n"
-"FIELD_DELIMITER               SPACE\n"
+"FIELD_DELIMITER               WHITESPACE\n"
 "RECORD_DELIMITER      NEWLINE\n"
 "BADCHARS              ,'\"\n"
 
index 740f124d2c7b1e69bec32f416fd89d831984d40f..5f0152818bbb5b8c45d94d2c52eb043731bac3de 100644 (file)
@@ -32,6 +32,19 @@ CRNEWLINE    \r\n
 TAB            \t
 SPACE                  <space>
 HASH           #
+WHITESPACE     *** SEE WHITESPACE NOTES BELOW ***
+
+WHITESPACE:
+The WHITESPACE constant has special properties.  When reading data, 
+WHITESPACE refers to sequential runs of SPACES and/or TABS.  When
+writing data, WHITESPACE is always a single SPACE.
+
+For example, the following line:
+SOME_NAME       30.1208 -91.1365    SOME OTHER NAME
+
+Parses into the following data fields: 
+SOME_NAME,30.1208,-91.1365,SOME,OTHER,NAME
+
 
 COMMENTS:
 Anything after a hash (#) on a line is not parsed.  For example:
@@ -40,6 +53,7 @@ Anything after a hash (#) on a line is not parsed.  For example:
 FIELD LAT_DECIMAL, "", "%f"  # ONLY THIS SENTENCE IS A COMMENT.
 
 
+
 GLOBAL PROPERTIES OF THE FILE:
 --------------------------------
 There are a few available directives to describe general traits of the 
index 96cbda45fa9716e3613fdf7ec9580e03ecba4de3..dfe80ccaa0307e62db29cef027856de8ef752331 100644 (file)
@@ -11,7 +11,7 @@ DESCRIPTION           GpsDrive Format
 
 # FILE LAYOUT DEFINITIIONS:
 #
-FIELD_DELIMITER                SPACE
+FIELD_DELIMITER                WHITESPACE
 RECORD_DELIMITER       NEWLINE
 BADCHARS               ,'"
 
index b2e09cecae93d30bff20c842ef6fcbd6b343eb71..9d16f4c14f2aea27a3507b59d73b9a6a8c836d49 100644 (file)
@@ -72,6 +72,7 @@ char_map_t xcsv_char_table[] = {
        { "TAB",                "\t"    },
        { "SPACE",              " "     },
        { "HASH",               "#"     },
+       { "WHITESPACE",         "\\w"   },
        { NULL,                 NULL    }
 };